/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nationsim.components.nation;

import java.util.Hashtable;
import nationsim.api.Constants;

/**
 *  Holds the state of a nation.
 * @author CJ
 */
public class NationState {
    
    protected Hashtable storage;
    
    public NationState(){
        this.storage = new Hashtable(Constants.UI_TEXT_INPUT_OPTIONS.length + NationStateValues.VALUES_DEFAULT.length);
        for(int i = 0; i < NationStateValues.VALUES_DEFAULT.length; ++i){
            this.storage.put(i, NationStateValues.VALUES_DEFAULT[i]);
        }
    }

    public void setUserInputTextValues(String[] input){
        if(input.length != Constants.UI_TEXT_INPUT_OPTIONS.length)
            throw new IllegalArgumentException("In NationState: setUserInputValues: Length of input is not the same as constant field!!");
        for(int i = 0 ; i < input.length; ++i)
            this.storage.put(Constants.UI_TEXT_INPUT_OPTIONS[i], input[i]);
    }

    public void setUserInputBarValues(Hashtable input){
        for(int i = 0; i < NationStateValues.USER_SET.length; ++i)
            this.storage.put(NationStateValues.USER_SET[i], input.get(i));
    }

    public Object getInstanceValue(Object key){
        return this.storage.get(key);
    }

    public void setInstanceValue(String name, String value){
        this.storage.put(name, value);
    }

    public void setInstanceValue(int name, String value){
        this.storage.put(name, value);
    }

    public String[] getUserInputValues(){
        String[] result = new String[Constants.UI_TEXT_INPUT_OPTIONS.length];
        for(int i = 0; i < result.length ; ++i)
            result[i] = (String)this.storage.get(Constants.UI_TEXT_INPUT_OPTIONS[i]);
        return result;
    }

    public String toString(){
        String[] textValues = new String[Constants.UI_TEXT_INPUT_OPTIONS.length];
        for(int i = 0; i < textValues.length ; ++i)
            textValues[i] = (String)this.storage.get(Constants.UI_TEXT_INPUT_OPTIONS[i]);
        String result = "";
        for(int i = 0; i < textValues.length; ++i){
            result += Constants.UI_TEXT_INPUT_OPTIONS[i] + " : " + textValues[i] + "\n";
        }
        result += "------------------\n";

        for(int i = 0; i < NationStateValues.VALUES_DEFAULT.length; ++i)
            result += NationStateValues.VALUE_NAME_LOOKUP[i] + " : " + this.storage.get(i).toString() + "\n";
        return result;
    }

    public NationState clone(){
        NationState result = new NationState();
        for(int i = 0; i < NationStateValues.VALUES_DEFAULT.length; ++i)
            result.storage.put(i, this.storage.get(i));
        for(int i = 0; i < Constants.UI_TEXT_INPUT_OPTIONS.length; ++i)
            result.storage.put(Constants.UI_TEXT_INPUT_OPTIONS[i], this.storage.get(Constants.UI_TEXT_INPUT_OPTIONS[i]));
        return result;
    }
}
